package leetcodecompetition.S111;

import java.util.List;

/**
 * @Author: Siantar
 * @Date: 2023-08-19-23:03
 * @Description: 1.0
 */
public class T6941 {
    public int minimumOperations(List<Integer> nums) {
        int n = nums.size();
        int[][] arr = new int[3][n + 1];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 3; j++) {
                arr[j][i + 1] = arr[j][i];
            }
            int d = nums.get(i);
            arr[d - 1][i + 1]++;
        }
        for (int i = 0; i < n+1; i++) {
            System.out.println(arr[0][i]+" "+arr[1][i]+" "+arr[2][i]+" ");
        }
        int res = Integer.MAX_VALUE;
        for (int i = 0; i < n + 1; i++) {
            int resTmp = Integer.MAX_VALUE;
            for (int j = i; j < n + 1; j++) {
                resTmp = Math.min(resTmp, (arr[0][j] + arr[2][j] - arr[0][i] - arr[2][i]) + (arr[0][n] + arr[1][n] - arr[0][j] - arr[1][j]));
                System.out.println(i+"  "+resTmp);
            }
            res = Math.min(res, resTmp + arr[1][i] + arr[2][i]);
        }
        return res;
    }
}
